{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# torch.utils.data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class torch.utils.data.Dataset\n",
    "表示Dataset的抽象类。\n",
    "所有其他数据集都应该进行子类化。所有子类应该override __len__ 和 __getitem__ ，前者提供了数据集的大小，后者支持整数索引，范围从0到len(self)。\n",
    "\n",
    "### class torch.utils.data.TensorDataset\n",
    "class torch.utils.data.TensorDataset(data_tensor, target_tensor)  \n",
    "包装数据和目标张量的数据集。\n",
    "通过沿着第一个维度索引两个张量来恢复每个样本。  \n",
    "参数：\n",
    "- data_tensor (Tensor) － 包含样本数据\n",
    "- target_tensor (Tensor) － 包含样本目标（标签）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class torch.utils.data.DataLoader\n",
    "class torch.utils.data.DataLoader(dataset, batch_size=1, shuffle=False, sampler=None, num_workers=0, collate_fn=< function default_collate>, pin_memory=False, drop_last=False)\n",
    "\n",
    "数据加载器。组合数据集和采样器，并在数据集上提供单进程或多进程迭代器。  \n",
    "参数：\n",
    "- dataset (Dataset) – 加载数据的数据集。\n",
    "- batch_size (int, optional) – 每个batch加载多少个样本(默认: 1)。\n",
    "- shufØe (bool, optional) – 设置为 True 时会在每个epoch重新打乱数据(默认: False).\n",
    "- sampler (Sampler, optional) – 定义从数据集中提取样本的策略。如果指定，则忽略shuffle 参数。\n",
    "- num_workers (int, optional) – 用多少个子进程加载数据。0表示数据将在主进程中加载(默认: 0)\n",
    "- collate_fn (callable, optional)\n",
    "- pin_memory (bool, optional)\n",
    "- drop_last (bool, optional) – 如果数据集大小不能被batch size整除，则设置为True后可删除最后一个不完整的batch。如果设为False并且数据集的大小不能被batch size整除，则最后一个batch将更小。(默认: False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class torch.utils.data.sampler.Sampler\n",
    "class torch.utils.data.sampler.Sampler(data_source)  \n",
    "所有采样器的基础类。  \n",
    "每个采样器子类必须提供一个 __iter__ 方法，提供一种迭代数据集元素的索引的方法，以及返回迭代器长度的 __len__ 方法"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class torch.utils.data.sampler.SequentialSampler\n",
    "class torch.utils.data.sampler.SequentialSampler(data_source)  \n",
    "样本元素顺序排列，始终以相同的顺序。  \n",
    "参数： \n",
    "- data_source (Dataset) – 采样的数据集"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class torch.utils.data.sampler.RandomSampler\n",
    "class torch.utils.data.sampler.RandomSampler(data_source)  \n",
    "样本元素随机，没有替换。  \n",
    "参数：   \n",
    "- data_source (Dataset) – 采样的数据集"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class torch.utils.data.sampler.SubsetRandomSampler\n",
    "class torch.utils.data.sampler.SubsetRandomSampler(indices)  \n",
    "样本元素从指定的索引列表中随机抽取，没有替换。  \n",
    "参数：   \n",
    "- indices (list) – 索引的列表"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class torch.utils.data.sampler.WeightedRandomSampler\n",
    "class torch.utils.data.sampler.WeightedRandomSampler(weights, num_samples, replacement=True)  \n",
    "样本元素来自于[0,..,len(weights)-1]，给定概率（weights）。  \n",
    "参数：   \n",
    "- weights (list) – 权重列表。没必要加起来为1 \n",
    "- num_samples (int) – 抽样数量"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
